class Trie {
public:
    Trie() {
        memset(son, 0, sizeof(son));
        memset(cnt, 0, sizeof(cnt));
    }

    void insert(string word) {
        int p = 0;
        for (int i = 0; i < word.size(); i++) {
            int x = word[i] - 'a';
            if (!son[p][x])
                son[p][x] = ++idx;
            p = son[p][x];
        }
        cnt[p]++;
    }

    bool search(string word) {
        int p = 0;
        for (int i = 0; i < word.size(); i++) {
            int x = word[i] - 'a';
            if (!son[p][x])
                return false;
            p = son[p][x];
        }
        return cnt[p];
    }

    bool startsWith(string prefix) {
        int p = 0;
        for (int i = 0; i < prefix.size(); i++) {
            int x = prefix[i] - 'a';
            if (!son[p][x])
                return false;
            p = son[p][x];
        }
        return true;
    }

private:
    const static int N = 1e5;
    int son[N][26], cnt[N];
    int idx = 0;
};

/**
 * Your Trie object will be instantiated and called as such:
 * Trie* obj = new Trie();
 * obj->insert(word);
 * bool param_2 = obj->search(word);
 * bool param_3 = obj->startsWith(prefix);
 */